#ifndef _CPU_H_
#define _CPU_H
#include "forco_os.h"
//用于定义和cpu相关的变量
typedef  unsigned int       CPU_UINT32;
typedef  int                CPU_INT32;
typedef  unsigned short     CPU_UINT16;
typedef  short              CPU_INT16;
typedef  unsigned char      CPU_UINT8;
typedef  char               CPU_INT8;

typedef  void   (*TASK_FUNCTION)(void* p_arg);
typedef  struct os_tcb          OS_TCB;
typedef  struct os_rdy_list     OS_RDY_LIST;
typedef  enum   os_err          OS_ERR;
typedef  struct os_tick_list    OS_TICK_LIST;



void OSCtxSw(void);
CPU_UINT32 CPU_CntLeadZeros(CPU_UINT32 val);
CPU_UINT32  CPU_SR_Save      (void);
void        CPU_SR_Restore   (CPU_UINT32      cpu_sr);

#define CPUNVIC_INT_CTRL    *((uint32_t *)0xE000ED04)
/*触发pensv中断*/
#define CPUNVIC_PENDSVSET   0x10000000
/*设置pendsv的中断优先级寄存器*/
#define  OS_TASK_SW()         OSCtxSw()

#define  CPU_SR_ALLOC()          CPU_UINT32  cpu_sr=0
#define  CPU_INT_DIS()         do { cpu_sr = CPU_SR_Save(); } while (0) 
#define  CPU_INT_EN()          do { CPU_SR_Restore(cpu_sr); } while (0)
#define  CPU_CRITICAL_ENTER()  do { CPU_INT_DIS(); } while (0)    //禁止中断     
#define  CPU_CRITICAL_EXIT()   do { CPU_INT_EN();  } while (0)    //打开中断

#define  OS_CRITICAL_EXIT()                     CPU_CRITICAL_EXIT()
#define  OS_CRITICAL_ENTER()                    CPU_CRITICAL_ENTER()


#endif

